//package com.csii.config.shiro;
//
//import com.csii.sso.client.filter.SsoJsonClientAuthenticationFilter;
//import com.csii.sso.client.utils.RedisClient;
//import org.apache.shiro.mgt.SecurityManager;
//import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.ImportResource;
//import org.springframework.context.annotation.PropertySource;
//
//import javax.servlet.Filter;
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.Map;
//
//@Configuration
////@PropertySource("classpath:sso/sso.properties")
//@ImportResource(locations= {"classpath:sso/sso-json-new.xml"})
//public class SsoShiroConfiguration {
//    @Value("${sso.server.url}")
//    private String loginUrl;
//    @Value("${sso.success.url}")
//    private String successUrl;
//    @Value("${sso.unauthorized.url}")
//    private String unauthorizedUrl;
//    @Value("${sso.api.url}")
//    private String ssoApiUrl;
//    @Value("${sso.login.url}")
//    private String ssoLoginUrl;
//    @Value("${app.frontend.url}")
//    private String appFrontendUrl;
//    @Value("${sso.global.session.timeout}")
//    private Integer timeout;
//    @Autowired
//    private RedisClient redisClient;
//
//    @Bean(name="shiroFilter")
//    public ShiroFilterFactoryBean shiroFilter(@Qualifier("securityManager") SecurityManager securityManager) {
//        ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
//        bean.setLoginUrl(loginUrl);
//        bean.setSuccessUrl(successUrl);
//        bean.setUnauthorizedUrl(unauthorizedUrl);
//        bean.setSecurityManager(securityManager);
//        Map<String, Filter> filters = new HashMap<>();
//        // 这里必须手动new
//        SsoJsonClientAuthenticationFilter ssoJsonClientAuthenticationFilter = new SsoJsonClientAuthenticationFilter();
//        ssoJsonClientAuthenticationFilter.setAppFrontendUrl(appFrontendUrl);
//        ssoJsonClientAuthenticationFilter.setSsoApiUrl(ssoApiUrl);
//        ssoJsonClientAuthenticationFilter.setSsoLoginUrl(ssoLoginUrl);
//        ssoJsonClientAuthenticationFilter.setRedisClient(redisClient);
//        ssoJsonClientAuthenticationFilter.setTimeout(timeout);
//        filters.put("authc", ssoJsonClientAuthenticationFilter);
//        bean.setFilters(filters);
//        // 这里必须用LinkedHashMap
//        LinkedHashMap<String, String> filterChainDefinitionMap=new LinkedHashMap<>();
////        filterChainDefinitionMap.put("/api.hello.do", "anon");// anon 匿名拦截器 不需要登录就能访问,一般用于静态资源,或者移动端接口
////        filterChainDefinitionMap.put("/upp.testUpp.do", "anon");
////        filterChainDefinitionMap.put("/upp.getUserRole.do", "anon");
////        filterChainDefinitionMap.put("/upp.hello.do","anon");
//        filterChainDefinitionMap.put("/index.html","anon");
//        filterChainDefinitionMap.put("/static/**","anon");
//        filterChainDefinitionMap.put("/**", "authc");// authc 登录拦截器 需要登录认证才能访问的资源
//        bean.setFilterChainDefinitionMap(filterChainDefinitionMap);
//        return bean;
//    }
//}
